<script type="text/javascript">
$("#create_user").click(function() {
    angular.element('#user_operation').scope().open(1, "/user_create");
})

function user_password(user_id) {
    angular.element('#user_operation').scope().open(user_id, '/user_password?user_id=' + user_id)
}

function user_delete(user_id) {
    $.get('/user_delete', {
            'id': user_id
        },
        function(data) {
            if (data.reply.is_success) {
                $('#user_grid_table').trigger("reloadGrid");
            } else {
                error = data.reply.error;
                SelfAlert(error)
            }
        });
}

function confirm_user_delete(user_id, username) {
    msg = '确定删除用户（' + username + '）？';
    SelfConfirm(msg, user_delete, user_id, "删除提示");
}

function user_update(user_id) {
    angular.element('#user_operation').scope().open(user_id, '/user_update?user_id=' + user_id)
}
$('#user_grid_table').jqGrid({
    url: '/grid_user',
    styleUI: 'Bootstrap',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['编号', '[["label name"|translate]]', '[["user user types"|translate]]', 'UserRole',
        '[["label copy"|translate]]', '[["label quota"|translate]](G)', "[['label Protection Domain'|translate]]",
        '[["label Creation time"|translate]]', '[["label operation"|translate]]',
    ],
    colModel: [{
        name: 'id',
        index: 'id',
        width: 6,
        align: '',
        hidden: true
    }, {
        name: 'name',
        index: 'name',
        width: 6,
        align: 'left',
        formatter: function(cellvalue, option, row) {
            return makeEllipsis(cellvalue,option);
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
    }, {
        name: 'rolename',
        index: 'rolename',
        width: 3,
        align: 'left',
        formatter: function(cell, option, row) {
            if (cell == 'administrator') {
                return "超级用户";
            }
            return "普通用户";
        }
    }, {
        name: 'identity',
        index: 'identity',
        width: 3,
        align: 'left',
        hidden: true,

    }, {
        name: 'repnum',
        index: 'repnum',
        width: 3,
        align: 'left',
        hidden: is_fusionnas, 
    }, {
        name: 'quota',
        index: 'quota',
        width: 3,
        align: 'left',
        hidden: is_fusionnas, 
    }, {
        name: 'show_protection_domains',
        index: 'show_protection_domains',
        width: 6,
        align: 'left',
        hidden: is_fusionnas, 
    }, {
        name: 'created_at',
        index: 'created_at',
        width: 6,
        align: 'left'
    }, {
        name: 'operation',
        index: 'operation',
        width: 8,
        align: 'left',
        detailHidden: true,
        formatter: function(cell, option, row) {
            row = row2object(row, option.gid);
            var html = '';
			{% if not is_fusionnas %}
            html += '<button title="编辑" class="btn btn-blue" onclick=user_update(' + row['id'] + ')>编辑</button>';
			{% endif %}
            html += '<button style="margin-left:10px;" title="修改密码" class="btn btn-blue" onclick=user_password(' + row['id'] + ')>修改密码</button>';
            if (row['name'] != 'admin') {
                html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue" onclick=confirm_user_delete(' + row['id'] + ',"' + row['name'] + '")>删除</button>';
            }
            return html;
        }
    }],
    page: 1,
    rowNum: 10,
    sortname: 'id',
    sortorder: 'asc',
    viewrecords: true,
    altclass: 'ui-priority-secondary',
    altRows: true,
    autowidth: true,
    height: mainpanelHeight,
    shrinkToFit: true,
    beforeSelectRow:function(rowid, e) {
        if($(e.target).is('input')) {
            return true;
        }
        return false;
    },
    gridComplete: function() {
        var gridData = $(this).jqGrid('getRowData');
        jqgrid_page($(this), gridData);
        jqgrid_resize($(this));
    },
});
        
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div id="user_operation" ng-controller="UserModalCtrl" ng-show="false"></div>
        <div class="title-tag">
            <h3>用户</h3>
            <p>用户管理</p>
        </div>
        <div class="grid-tools">
            <!-- <div class="grid-search-down-arrow">
                <i class="fa fa-angle-down"></i>
            </div> -->
            <div class="grid-operate pull-left">
                <button class="btn btn-blue" id="create_user" type="button">[['user Create user'|translate]]</button>
            </div>
        </div>
        <div class="grid-body" id="div_user_available_tb">
            <table id="user_grid_table"></table>
        </div>
    </div>
</div>
<!-- 
<div class="panel panel-default">
        <div class="panel-body">
                <div class="item_toolsbar">
                        <span class="message_img">&nbsp;</span> 
                        <input type="button" id='create_user' value="[['user Create user'|translate]]" class="button button_gray"/>&nbsp;
                </div>
                <div id="div_user_available_tb" class='tab_warp'>
                        <table id="user_grid_table"></table>
                </div>
        </div> panel-body
</div> -->
